<template>
  <el-dialog
    :title="!dataForm.reportId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="诊断序号id" prop="clinicalId">
      <el-input v-model="dataForm.clinicalId" placeholder="诊断序号id"></el-input>
    </el-form-item>
    <el-form-item label="诊断时间" prop="reportTime">
      <el-input v-model="dataForm.reportTime" placeholder="诊断时间"></el-input>
    </el-form-item>
    <el-form-item label="诊断价格" prop="reportMoney">
      <el-input v-model="dataForm.reportMoney" placeholder="诊断价格"></el-input>
    </el-form-item>
    <el-form-item label="病因" prop="reportCause">
      <el-input v-model="dataForm.reportCause" placeholder="病因"></el-input>
    </el-form-item>
    <el-form-item label="诊断描述" prop="reportMessage">
      <el-input v-model="dataForm.reportMessage" placeholder="诊断描述"></el-input>
    </el-form-item>
    <el-form-item label="诊断结果" prop="reportResult">
      <el-input v-model="dataForm.reportResult" placeholder="诊断结果"></el-input>
    </el-form-item>
    <el-form-item label="支付方式" prop="reportType">
      <el-input v-model="dataForm.reportType" placeholder="支付方式"></el-input>
    </el-form-item>
    <el-form-item label="年龄" prop="reportAge">
      <el-input v-model="dataForm.reportAge" placeholder="年龄"></el-input>
    </el-form-item>
    <el-form-item label="体重" prop="reportWeight">
      <el-input v-model="dataForm.reportWeight" placeholder="体重"></el-input>
    </el-form-item>
    <el-form-item label="身高" prop="reportHight">
      <el-input v-model="dataForm.reportHight" placeholder="身高"></el-input>
    </el-form-item>
    <el-form-item label="婚姻状态" prop="reportMarital">
      <el-input v-model="dataForm.reportMarital" placeholder="婚姻状态"></el-input>
    </el-form-item>
    <el-form-item label="肾功能" prop="reportShen">
      <el-input v-model="dataForm.reportShen" placeholder="肾功能"></el-input>
    </el-form-item>
    <el-form-item label="肝功能" prop="reportGan">
      <el-input v-model="dataForm.reportGan" placeholder="肝功能"></el-input>
    </el-form-item>
    <el-form-item label="生育状态" prop="reportFertility">
      <el-input v-model="dataForm.reportFertility" placeholder="生育状态"></el-input>
    </el-form-item>
    <el-form-item label="酒静状态" prop="reportBeer">
      <el-input v-model="dataForm.reportBeer" placeholder="酒静状态"></el-input>
    </el-form-item>
    <el-form-item label="好评分数" prop="reportHappy">
      <el-input v-model="dataForm.reportHappy" placeholder="好评分数"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          reportId: 0,
          clinicalId: '',
          reportTime: '',
          reportMoney: '',
          reportCause: '',
          reportMessage: '',
          reportResult: '',
          reportType: '',
          reportAge: '',
          reportWeight: '',
          reportHight: '',
          reportMarital: '',
          reportShen: '',
          reportGan: '',
          reportFertility: '',
          reportBeer: '',
          reportHappy: ''
        },
        dataRule: {
          clinicalId: [
            { required: true, message: '诊断序号id不能为空', trigger: 'blur' }
          ],
          reportTime: [
            { required: true, message: '诊断时间不能为空', trigger: 'blur' }
          ],
          reportMoney: [
            { required: true, message: '诊断价格不能为空', trigger: 'blur' }
          ],
          reportCause: [
            { required: true, message: '病因不能为空', trigger: 'blur' }
          ],
          reportMessage: [
            { required: true, message: '诊断描述不能为空', trigger: 'blur' }
          ],
          reportResult: [
            { required: true, message: '诊断结果不能为空', trigger: 'blur' }
          ],
          reportType: [
            { required: true, message: '支付方式不能为空', trigger: 'blur' }
          ],
          reportAge: [
            { required: true, message: '年龄不能为空', trigger: 'blur' }
          ],
          reportWeight: [
            { required: true, message: '体重不能为空', trigger: 'blur' }
          ],
          reportHight: [
            { required: true, message: '身高不能为空', trigger: 'blur' }
          ],
          reportMarital: [
            { required: true, message: '婚姻状态不能为空', trigger: 'blur' }
          ],
          reportShen: [
            { required: true, message: '肾功能不能为空', trigger: 'blur' }
          ],
          reportGan: [
            { required: true, message: '肝功能不能为空', trigger: 'blur' }
          ],
          reportFertility: [
            { required: true, message: '生育状态不能为空', trigger: 'blur' }
          ],
          reportBeer: [
            { required: true, message: '酒静状态不能为空', trigger: 'blur' }
          ],
          reportHappy: [
            { required: true, message: '好评分数不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.reportId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.reportId) {
            this.$http({
              url: this.$http.adornUrl(`/medical/diagnose/info/${this.dataForm.reportId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.clinicalId = data.diagnose.clinicalId
                this.dataForm.reportTime = data.diagnose.reportTime
                this.dataForm.reportMoney = data.diagnose.reportMoney
                this.dataForm.reportCause = data.diagnose.reportCause
                this.dataForm.reportMessage = data.diagnose.reportMessage
                this.dataForm.reportResult = data.diagnose.reportResult
                this.dataForm.reportType = data.diagnose.reportType
                this.dataForm.reportAge = data.diagnose.reportAge
                this.dataForm.reportWeight = data.diagnose.reportWeight
                this.dataForm.reportHight = data.diagnose.reportHight
                this.dataForm.reportMarital = data.diagnose.reportMarital
                this.dataForm.reportShen = data.diagnose.reportShen
                this.dataForm.reportGan = data.diagnose.reportGan
                this.dataForm.reportFertility = data.diagnose.reportFertility
                this.dataForm.reportBeer = data.diagnose.reportBeer
                this.dataForm.reportHappy = data.diagnose.reportHappy
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/medical/diagnose/${!this.dataForm.reportId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'reportId': this.dataForm.reportId || undefined,
                'clinicalId': this.dataForm.clinicalId,
                'reportTime': this.dataForm.reportTime,
                'reportMoney': this.dataForm.reportMoney,
                'reportCause': this.dataForm.reportCause,
                'reportMessage': this.dataForm.reportMessage,
                'reportResult': this.dataForm.reportResult,
                'reportType': this.dataForm.reportType,
                'reportAge': this.dataForm.reportAge,
                'reportWeight': this.dataForm.reportWeight,
                'reportHight': this.dataForm.reportHight,
                'reportMarital': this.dataForm.reportMarital,
                'reportShen': this.dataForm.reportShen,
                'reportGan': this.dataForm.reportGan,
                'reportFertility': this.dataForm.reportFertility,
                'reportBeer': this.dataForm.reportBeer,
                'reportHappy': this.dataForm.reportHappy
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
